
doJoin = function(){
	location.href = CONSTANT_SITE_URL + "/member.do?todo=step1FormSSL";
};

doMemInfo = function(){
	location.href = CONSTANT_SITE_URL + "/member.do?todo=memberFormSSL";
};

doLogin = function(){
	location.href = CONSTANT_SITE_URL + "/global.do?todo=loginFormSSL";
};

doLogout = function(GUBUN, BROWSER){
	if(BROWSER != "iPhone" || BROWSER != "iPad") {
		document.cookie = "iPadOrderStep2=" + "; path=/; ";
		document.cookie = "iPadOrderStep3=" + "; path=/; ";
		document.cookie = "iPadOrderStep4=" + "; path=/; ";
	}
	/*
	var result = true;
	if(mobileApp) {
		result = mobileApp.callLogout();
	}
	if (result) {
		location.href = "/global.do?todo=logout";
	}
	*/
	
	if(mobileApp) {
		mobileApp.callLogout();
	}
	setTimeout(function(){ // App 함수 호출을 위한 delay
		if(GUBUN == "M"){
			cookieManager.setCookie("VIEW", "mobile", null, "/", cookieManager.getDomain()); // CDN 페이지에서 호출되는 경우때문에 모바일일 경우 쿠키 심음
			location.href = CONSTANT_MOBILE_URL + "/global.do?todo=logout";
		}else{
			location.href = CONSTANT_SITE_URL + "/global.do?todo=logout";
		}
    }, 50);
	
};

//탭
function over(imgName) {
	imgName.getElementsByTagName("img").item(0).src = imgName.getElementsByTagName("img").item(0).src.replace(/(_on.gif|.gif)$/i, "_on.gif");
	imgName.getElementsByTagName("img").item(0).src = imgName.getElementsByTagName("img").item(0).src.replace(/(_on.jpg|.jpg)$/i, "_on.jpg");
}
function out(imgName) {
	imgName.getElementsByTagName("img").item(0).src = imgName.getElementsByTagName("img").item(0).src.replace(/(_on.gif|.gif)$/i, ".gif");
	imgName.getElementsByTagName("img").item(0).src = imgName.getElementsByTagName("img").item(0).src.replace(/(_on.jpg|.jpg)$/i, ".jpg");
}

/*
function doLogout(){
	jQuery.ajax({
		type : "POST",
		url : "/global.do?todo=doLogout",
		cache : false,
		dataType : "xml",
		success : function(xml){
			if ($(xml).find("result").length > 0 ){
				alert($(xml).find("result").attr("msg"));
			} else {
				alert("로그아웃 오류");
			}
		}
	});
}
*/

function over(obj) {
	var imgObj = $(obj).children('img');
	$(imgObj).attr('src', $(imgObj).attr('src').replace(/(_on.gif|.gif)$/i, "_on.gif"));
	$(imgObj).attr('src', $(imgObj).attr('src').replace(/(_on.jpg|.jpg)$/i, "_on.jpg"));
}
function out(obj) {
	var imgObj = $(obj).children('img');
	$(imgObj).attr('src', $(imgObj).attr('src').replace(/(_on.gif|.gif)$/i, ".gif"));
	$(imgObj).attr('src', $(imgObj).attr('src').replace(/(_on.jpg|.jpg)$/i, ".jpg"));
	/*
	var imgObj = obj.getElementsByTagName("img").item(0);
	imgObj.src = imgObj.src.replace(/(_on.gif|.gif)$/i, ".gif");
	imgObj.src = imgObj.src.replace(/(_on.jpg|.jpg)$/i, ".jpg");
	*/
}
function gnb(obj){
	var idx = $(obj).parent().index('.depth1');
	$('.gnb_menu li.depth1').each(function(i){
		if ( i==idx){
			over($(this).children('a'));
			$(this).children('ul').show();
			$(this).children('ul').mouseleave(function(){
				$(this).hide();
			});
		} else {
			out($(this).children('a'));
			$(this).children('ul').hide();
		}
	});
}
function gnbOut(){

}

// jquery toggle 사용 하면 될듯
function hover_layer(className){
	if ($("."+className).css("display") == "none") {
		$("."+className).show();
	}else{
		$("."+className).hide();
	}
}

function menu_sub(n){
	$(".menu_title dd").find(".submenu").hide();
	$(".menu_title dd").eq(n-1).find(".submenu").show();
}
function menu_sub_hide(n){
	$(".menu_title dd").find(".submenu").hide();
}


function chkTweetLinks(s){
	var regLink = new RegExp('(http|https|ftp|telnet|news|irc)://([-/.a-zA-Z0-9_~#%$?&=:200-377()]+)','gi');
	var r = s.replace(regLink,'<a href="$1://$2" target="_blank">$1://$2</a>')
		.replace(/(^|\s)@(\w+)/g, '$1@<a href="http://www.twitter.com/$2" target="_blank">$2</a>')
		.replace(/(^|\s)#(\w+)/g, '$1#<a href="http://search.twitter.com/search?q=%23$2" target="_blank">$2</a>');
	return r;
}
function date_diff(timeStr) {
	var values = timeStr.split(' '),
		parsed_date = Date.parse(values[1] + ' ' + values[2] + ', ' + values[5] + ' ' + values[3] + ' GMT+0900'),
//		parsed_date = Date.parse(values[1] + ' ' + values[2] + ', ' + values[5] + ' ' + values[3] + ' '),
		date = new Date(parsed_date),
		now_date = new Date(),
		diff_sec = ( now_date.getTime()  - date.getTime() ) / 1000,
		diff_min = diff_sec / 60,
		diff_hour = diff_min / 60,
		diff_date = ( Date.UTC(now_date.getFullYear(), now_date.getMonth(), now_date.getDate())
					- Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()) )
					/1000/60/60/24,
		r = '';

	if (diff_sec < 5) {
        r = '5초 이내';
    } else if (diff_sec < 30) {
        r = '30초 이내';
    } else if (diff_sec < 60) {
        r = '1분 이내';
    } else if (diff_sec < 120) {
        r = '1분 전';
    } else if (diff_sec < (45*60)) {
        r = (parseInt(diff_min)).toString() + '분 전';
    //} else if (diff_sec < (2*45*60)) { // 2* because sometimes read 1 hours ago
      //  r = '약 1시간 전';
    } else if (diff_sec < (24*60*60)) {
        r = '약 ' + parseInt( Math.round(diff_hour) ) + '시간 전'; //반올림
    } else if ( diff_date == 1 ) {
    	r = '어제 '+formatTime(date);
    } else if (diff_date < 7) {
        r = diff_date.toString() + '일 전 '+formatTime(date);
    }
    else {
       	r = date.toDateString();
    }

    return r;
}
function formatTime(date) {
    var hour = date.getHours(),
        min = date.getMinutes() + '',
        ampm = 'AM';

    if (hour == 0) { hour = 12; }
    else if (hour == 12) { ampm = 'PM'; }
    else if (hour > 12) { hour -= 12; ampm = 'PM'; }

    if (min.length == 1) min = '0' + min;

    return hour + ':' + min + ' ' + ampm;
}
function goPcView(type){
	cookieManager.setCookie("VIEW", "PC", null, "/", cookieManager.getDomain());
//	cookieManager.clearCookie("BASKET");
	var expireDate = new Date();
 	expireDate.setDate(expireDate.getDate() - 1);
	document.cookie = "BASKET=" + "; expires=" + expireDate.toGMTString()+"; domain=" + cookieManager.getDomain();
	if(type == "M")
		document.location.href=CONSTANT_SITE_URL;
	else if(type == "L")
		document.location.href=CONSTANT_SITE_URL + "/etc.do?todo=law";
	else if(type == "P")
		document.location.href=CONSTANT_SITE_URL + "/etc.do?todo=privacy";
}
/**
 * 로그인 상태 표시
 */
function initTopmenu(LANG) {
	var auth = cookieManager.getCookie('AUTH');
	var myCouponCnt = cookieManager.getCookie('MY_CUPN_CNT');
	var topmenu_auth1_str = '';
	var topmenu_auth2_str = '';

	if(!auth.isBlank()) { // 로그인 상태
		topmenu_auth1_str = '<a href="javascript:doLogout();"><img src="'+CONSTANT_WEBSRC_URL+'/images/topmenu_04.gif?v5" alt="로그아웃" /></a>';
		if(!myCouponCnt.isBlank()){
			topmenu_auth2_str = '<a href="javascript:clickButton(\'050305\');" class="m7"><img src="'+CONSTANT_WEBSRC_URL+'/images/topmenu_07.gif?v5" alt="My 쿠폰" />';
			topmenu_auth2_str += '('+myCouponCnt+')';
			topmenu_auth2_str += '</a>';
		}
		topmenu_auth2_str += '<a href="javascript:clickButton(\'050300\');"><img src="'+CONSTANT_WEBSRC_URL+'/images/topmenu_08.gif?v5" alt="나의 정보" /></a>';
	} else {
		topmenu_auth1_str = '<a href="javascript:clickButton(\'050100\');"><img src="'+CONSTANT_WEBSRC_URL+'/images/topmenu_01.gif?v5" alt="로그인" /></a>';
		topmenu_auth2_str = '<a href="javascript:clickButton(\'050200\');"><img src="'+CONSTANT_WEBSRC_URL+'/images/topmenu_02.gif?v5" alt="회원가입" /></a>';
	}
	$('#topmenu_auth1').html(topmenu_auth1_str);
	$('#topmenu_auth2').html(topmenu_auth2_str);
}
/**
 * 모바일 로그인 상태 표시
 */
function initMobileTopmenu() {
	var auth = cookieManager.getCookie('AUTH');
	var topmenu_auth1 = '';
	$('#topmenu_auth1').empty();
	if(!auth.isBlank()) { // 로그인 상태
		topmenu_auth1 = '<div id="topmenu_auth1" class="btn_login"><a href="javascript:doLogout(\'M\');"><img src="'+CONSTANT_WEBSRC_URL+'/img/btn_logout.png" alt="LOGOUT" alt="로그아웃" width="43" height="14" /></a></div>';
	} else {
		topmenu_auth1 = '<div id="topmenu_auth1" class="btn_login"><a href="javascript:goLogin();"><img src="'+CONSTANT_WEBSRC_URL+'/img/btn_login.png" alt="로그인" width="43" height="14" /></a></div>';
	}
	$('#topmenu_auth1').html(topmenu_auth1);
}
/**
 * 모바일 풋터 표시
 */
function initMobileFootermenu() {
	var auth = cookieManager.getCookie('AUTH');
	var footermenu_auth1 = '';
	$('.topmenu_auth').empty();
	if(!auth.isBlank()) { // 로그인 상태
		footermenu_auth1 = '<img src="'+CONSTANT_WEBSRC_URL+'/img/footer_01_on.png" alt="" width="266"  usemap="#footermapon" />';
		footermenu_auth1 += '<map name="footermapon" id="footermapon">';
		footermenu_auth1 += '<area shape="rect" coords="3,1,43,13" href="javascript:doLogout(\'M\')" alt="로그아웃"  title="로그아웃">';
		footermenu_auth1 += '<area shape="rect" coords="75,1,116,13" href="javascript:navi(10016);" alt="나의정보" title="나의정보">';
		footermenu_auth1 += '<area shape="rect" coords="148,1,187,12" href="javascript:navi(10002);" alt="PC버전" title="PC버전">';
		footermenu_auth1 += '<area shape="rect" coords="219,0,260,11" href="javascript:shwoCustomerCenter(\'1\');" alt="고객센터" title="고객센터">';
		footermenu_auth1 += '<area shape="rect" coords="84,19,154,29" href="'+CONSTANT_MOBILE_URL+'/etc.do?todo=privacy" alt="개인정보취급방침" title="개인정보취급방침">';
		footermenu_auth1 += '<area shape="rect" coords="162,18,200,29" href="'+CONSTANT_MOBILE_URL+'/etc.do?todo=law" alt="이용약관" title="이용약관">';
		footermenu_auth1 += '<area shape="rect" coords="210,19,267,29" href="'+CONSTANT_MOBILE_URL+'/bbs.do?todo=getFaqList&bbs_cd=online" alt="자주묻는질문" title="자주묻는질문">';
		footermenu_auth1 += '</map>';
	} else {
		footermenu_auth1 = '<img src="'+CONSTANT_WEBSRC_URL+'/img/footer_01.png" alt="" width="266"  usemap="#footermap" />';	
		footermenu_auth1 += '<map name="footermap" id="footermap">';
		footermenu_auth1 += '<area shape="rect" coords="3,1,43,13" href="javascript:goLogin();" alt="로그인"  title="로그인">';
		footermenu_auth1 += '<area shape="rect" coords="75,1,116,13" href="'+CONSTANT_MOBILE_URL+'/member.do?todo=step1FormSSL" alt="회원가입" title="회원가입">';
		footermenu_auth1 += '<area shape="rect" coords="148,1,187,12" href="javascript:navi(10002);" alt="PC버전" title="PC버전">';
		footermenu_auth1 += '<area shape="rect" coords="219,0,260,11" href="javascript:shwoCustomerCenter(\'1\');" alt="고객센터" title="고객센터">';
		footermenu_auth1 += '<area shape="rect" coords="84,19,154,29" href="'+CONSTANT_MOBILE_URL+'/etc.do?todo=privacy" alt="개인정보취급방침" title="개인정보취급방침">';
		footermenu_auth1 += '<area shape="rect" coords="162,18,200,29" href="'+CONSTANT_MOBILE_URL+'/etc.do?todo=law" alt="이용약관" title="이용약관">';
		footermenu_auth1 += '<area shape="rect" coords="210,19,267,29" href="'+CONSTANT_MOBILE_URL+'/bbs.do?todo=getFaqList&bbs_cd=online" alt="자주묻는질문" title="자주묻는질문">';
		footermenu_auth1 += '</map>';	
	}
	$('#footermenu_auth1').html(footermenu_auth1);
}
// EOF